package com.gmlive.plugin.jenkins

import com.google.gson.Gson
import okhttp3.FormBody
import okhttp3.MediaType
import okhttp3.OkHttpClient
import okhttp3.Request
import org.json.JSONObject

object ApmServiceUtils {


    fun sendBuildApkMsg(apkUrl:String){
        kotlin.runCatching {
            val client = OkHttpClient()
            val bodyJsonObj = JSONObject().apply {
                put("Platform", "android")
                put("DownloadUrl", apkUrl)
            }.toString()

            log(bodyJsonObj)

            val body = FormBody.create(MediaType.parse("application/json; charset=utf-8"), bodyJsonObj)

            val request = Request.Builder()
                .url("http://app-diff-test.inkegd.com/release/add")
                .post(body)
                .build()

            val response = client.newCall(request).execute()

            log("${response.body()?.string()}")
        }.onFailure {
            log("error:")
            it.printStackTrace()
        }


    }

    private fun log(msg:String){
        println("[Jenkins] ApmServiceSend：$msg")
    }
}